﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FoneBuddy.LinqModel;
using FoneBuddy.LinqModel.Data;
using FoneBuddy.LinqData;

public partial class Category_List : System.Web.UI.Page
{
    //IDataRepository _dataObject = new DataRepository();
    IDataRepository _dataObject = new DataRepository();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            getFilterDetail();
        }
    }

    #region BindData
    private void getFilterDetail()
    {
        FilterDetail filterdetail;
        List<FilterDetail> filterDetails = new List<FilterDetail>();
        filterdetail = new FilterDetail(_dataObject);

        filterDetails = filterdetail.GetAllFilterDetail().Where(w => w.FilterMaster.Name == EnumClass.Enums.Filter.Category.ToString() ).ToList();

        if (filterDetails != null)
        {
            rptCategory.DataSource = filterDetails;
            rptCategory.DataBind();
        }
    }
    #endregion

    #region webmethod for edit
    [System.Web.Services.WebMethod]
    public static string Update(string name, string id)
    {
        FilterDetail filter = new FilterDetail();
        IDataRepository _dataObject = new DataRepository();
        filter = new FilterDetail(_dataObject);
        filter.FilterId = (Int32)EnumClass.Enums.Filter.Category;
        filter.Name = name;
        if (id == "")
            filter.Id = 0;
        else
            filter.Id = Convert.ToInt32(id);

        filter.GetFilterDetailByName();
        if (id != "")
        {
            if (filter.Id != Convert.ToInt32(id) && filter.Id != 0)
            {
                return "0";
            }
            else
            {
                filter.UpdatedDate = System.DateTime.Now;
                filter.IsDeleted = false;
                filter.Update();
                return filter.Id.ToString();
            }
        }
        else
        {
            if (filter.Id > 0)
            {
                return "0";
            }
            else
            {
                filter.CreatedDate = System.DateTime.Now;
                filter.Create();
                return filter.Id.ToString();
            }
        }
    }
    #endregion

    #region WebMethod for Delete
    [System.Web.Services.WebMethod]
    public static string Delete(string id)
    {
        try
        {

            FoneBuddy.LinqModel.FilterDetail filter = new FilterDetail();
            IDataRepository _dataObject = new DataRepository();
            filter = new FilterDetail(_dataObject);
            filter.Id = Convert.ToInt32(id);
            filter.Delete();
            return "Deleted";
        }
        catch
        {
            return "error";
        }

    }
    #endregion
}